local V3tool= _G.CommonOHOH.load.Vector3Tool()
local InstanceManager = _G.CommonOHOH.load.InstanceManager();


local M={}

--寻找距离怪物最近的玩家,list,为自定义player数组
function M.FindClosestDistancePlayer(monster,list)

     local min =math.huge
     local minP=nil
     for _,player in pairs(list) do

        if not player.character then
            continue
        end

        local v1= monster:GetPosition()
        local v2=player.character:GetPosition()
         local d=V3tool.SqrMagnitude(v1,v2)
         if d<min then
            min=d
            minP=player
         end
    end
     return minP
end

--寻找距离怪物最近的玩家,list,为系统player数组
function M.FindClosestDistancePlayerInst(monster,list)

    local playerList={}

    for _,inst in pairs(list) do
        local player= InstanceManager:FindObject(inst)
        table.insert(playerList,player)
    end

    return M.FindClosestDistancePlayer(monster,playerList)
end



return M